package com.aspose.cells;

import java.util.HashMap;
import java.util.Iterator;

class zbvi {
   private Workbook a;
   private WorksheetCollection b;
   private zbpx c;
   private zbvx d;
   private boolean e;
   private Cells f;
   private RowCollection g;
   private TxtLoadOptions h;
   private HashMap i;
   private zhm j;
   private zhb k;
   private zatf l = null;
   private zfv m = new zfv();
   private HashMap n = null;
   private ICustomParser[] o;
   private boolean p;
   private boolean q;
   private static final com.aspose.cells.b.c.a.za r = new com.aspose.cells.b.c.a.za(new String[]{"TRUE", "FALSE"});

   private zbvi(Cells var1, TxtLoadOptions var2) {
      this.f = var1;
      this.b = var1.r();
      this.a = this.b.n();
      this.g = var1.getRows();
      WorkbookSettings var3 = this.a.getSettings();
      this.p = var3.getDate1904();
      this.q = var3.getCheckExcelRestriction();
      this.c = this.b.g;
      this.i = this.c.a();
      this.d = this.b.B();
      this.h = var2;
      this.o = var2.getPreferredParsers();
      if (this.o != null) {
         this.l = new zatf();
      }

      if (var2.getConvertNumericData()) {
         this.j = var3.e().h();
         this.l = new zatf();
         if (var2.d()) {
            this.n = new HashMap();
         }
      }

      if (var2.getConvertDateTimeData()) {
         this.k = var3.e().i();
         if (!var2.getConvertNumericData()) {
            this.l = new zatf();
            if (var2.d()) {
               this.n = new HashMap();
            }
         }
      }

   }

   static void a(String var0, Cells var1, int var2, int var3, TxtLoadOptions var4) throws Exception {
      (new zbvi(var1, var4)).a(var0, var2, var3);
   }

   static void a(com.aspose.cells.b.a.d.zn var0, Cells var1, int var2, int var3, TxtLoadOptions var4) throws Exception {
      (new zbvi(var1, var4)).a(var0, var2, var3);
   }

   private zati a(String var1, int var2) {
      if (var1 != null && !"".equals(var1)) {
         if (this.o != null) {
            ICustomParser var3 = this.o[var2 < this.o.length ? var2 : this.o.length - 1];
            if (var3 != null) {
               Object var4 = var3.parseObject(var1);
               if (var4 != null) {
                  this.l.a(6);
                  this.l.a(var4);
                  this.l.a(var3.getFormat());
                  return this.l;
               }
            }
         }

         switch(r.a(var1.toUpperCase())) {
         case 0:
            this.l.a(0);
            this.l.a(zml.d);
            this.l.a((String)null);
            return this.l;
         case 1:
            this.l.a(0);
            this.l.a(zml.e);
            this.l.a((String)null);
            return this.l;
         default:
            if (this.i.get(var1) != null) {
               return null;
            } else if (this.h.getConvertNumericData() && this.j.parseObject(var1) != null) {
               return this.j.a();
            } else {
               return this.h.getConvertDateTimeData() && this.k.parseObject(var1) != null ? this.k.a() : null;
            }
         }
      } else {
         return null;
      }
   }

   private int a(zp var1, int var2, int var3, int var4, int var5, StringBuilder var6) {
      if (var6.length() == 0) {
         return var3;
      } else {
         String var7 = com.aspose.cells.b.a.zr.a(var6);
         var3 = var1.a(var4, var3);
         if (var3 > -1) {
            switch(var1.h(var3)) {
            case 4:
            case 5:
               Cell var8 = new Cell(new Row(this.f, this.g, var1, false), var3);
               var8.e();
            }
         }

         if ((this.h.getConvertNumericData() || this.h.getConvertDateTimeData()) && var7.length() < 30) {
            Object var15 = this.h.d() ? this.n.get(var7) : null;
            int var12;
            if (var15 != null) {
               zfv var9;
               if (this.e) {
                  if (var3 < 0) {
                     var3 = -var3 - 1;
                     var9 = (zfv)var15;
                     var9.a = (short)var4;
                     var1.a(var3, var9);
                  } else {
                     var1.b(var3, (zfv)var15, 6);
                  }
               } else {
                  Object[] var10;
                  zfv var11;
                  int var16;
                  if (var3 < 0) {
                     var3 = -var3 - 1;
                     if (var15 instanceof zfv) {
                        var9 = (zfv)var15;
                        var9.a = (short)var4;
                        var1.a(var3, var9);
                     } else {
                        var16 = Cell.a(this.f, var2, var4);
                        var10 = (Object[])((Object[])var15);
                        var11 = (zfv)var10[0];
                        var11.a = (short)var4;
                        if (var16 < 0) {
                           if (var11.b < 0) {
                              var11.b = this.d.a((Integer)var10[2], (String)var10[1], -1);
                           }

                           var1.a(var3, var11);
                        } else {
                           var12 = var11.b;
                           var11.b = this.d.a((Integer)var10[2], (String)var10[1], var16);
                           var1.a(var3, var11);
                           var11.b = var12;
                        }
                     }
                  } else if (var15 instanceof zfv) {
                     var9 = (zfv)var15;
                     var1.b(var3, var9);
                  } else {
                     var16 = var1.g(var3);
                     if (var16 < 0) {
                        var16 = Cell.a(this.f, var2, var4);
                     }

                     var10 = (Object[])((Object[])var15);
                     var11 = (zfv)var10[0];
                     if (var16 < 0) {
                        if (var11.b < 0) {
                           var11.b = this.d.a((Integer)var10[2], (String)var10[1], -1);
                        }

                        var1.b(var3, var11, 6);
                     } else {
                        var12 = var11.b;
                        var11.b = this.d.a((Integer)var10[2], (String)var10[1], var16);
                        var1.b(var3, var11, 6);
                        var11.b = var12;
                     }
                  }
               }
            } else {
               this.m.a(var4);
               zati var18 = this.a(var7, var4 - var5);
               if (var18 != null) {
                  String var17 = var18.e();
                  int var19 = -1;
                  switch(var18.a()) {
                  case 0:
                     this.m.c = 2;
                     this.m.d = var18.d();
                     break;
                  case 1:
                     DateTime var21 = (DateTime)var18.d();
                     double var13 = zbtq.a(var21, this.p);
                     if (var13 < 0.0D) {
                        this.m.c = 4;
                        this.m.d = this.c.a(var7);
                        var17 = null;
                     } else {
                        if (!this.h.getKeepExactFormat()) {
                           var19 = var18.b();
                        }

                        zavz.a(var13, this.m);
                     }
                     break;
                  case 2:
                  case 3:
                  default:
                     if (!this.m.a(var18.d(), true)) {
                        this.m.c = 4;
                        String var22 = com.aspose.cells.b.a.zr.a(this.m.d);
                        if (this.q && var22.length() > 32767) {
                           zgy.a(CellsHelper.cellIndexToName(var1.h(), var4));
                        }

                        this.m.d = this.c.a(var22);
                     }
                     break;
                  case 4:
                     zatj var20 = (zatj)var18;
                     zavz.a(var20.i(), this.m);
                     if (!this.h.getKeepExactFormat() && var17 != null) {
                        var19 = var18.b();
                     }
                  }

                  if (var3 < 0) {
                     var3 = -var3 - 1;
                     if (var19 <= -1 && var17 == null) {
                        if (this.h.d()) {
                           this.n.put(var7, new zfv(this.m));
                        }
                     } else if (this.e) {
                        this.m.b = this.d.a(var19, var17, -1);
                        if (this.h.d()) {
                           this.n.put(var7, new zfv(this.m));
                        }
                     } else {
                        var12 = Cell.a(this.f, var2, var4);
                        this.m.b = this.d.a(var19, var17, var12);
                        if (this.h.d()) {
                           zfv var23 = new zfv(this.m);
                           if (var12 > -1 && var12 != 15) {
                              var23.b = -1;
                           }

                           this.n.put(var7, new Object[]{var23, var17, var19});
                        }
                     }

                     var1.a(var3, this.m);
                  } else if (var19 <= -1 && var17 == null) {
                     if (this.h.d()) {
                        this.n.put(var7, new zfv(this.m));
                     }

                     var1.b(var3, this.m);
                  } else {
                     var12 = var1.g(var3);
                     if (var12 < 0) {
                        var12 = Cell.a(this.f, var2, var4);
                     }

                     this.m.b = this.d.a(var19, var17, var12);
                     if (this.h.d()) {
                        this.n.put(var7, new zfv(this.m));
                     }

                     var1.b(var3, this.m, 6);
                  }
               } else {
                  var3 = this.a(var1, var3, var4, var7);
               }
            }
         } else {
            this.m.a(var4);
            var3 = this.a(var1, var3, var4, var7);
         }

         var6.delete(0, 0 + var6.length());
         return var3;
      }
   }

   private int a(zp var1, int var2, int var3, String var4) {
      if (this.q && var4.length() > 32767) {
         zgy.a(CellsHelper.cellIndexToName(var1.h(), var3));
      }

      byte var5 = zsk.a(var4);
      if (var5 != -1) {
         this.m.c = 3;
         this.m.d = com.aspose.cells.a.c.zi.a(var5);
      } else {
         this.m.c = 4;
         this.m.d = this.c.a(var4);
      }

      if (var2 < 0) {
         var2 = -var2 - 1;
         var1.a(var2, this.m);
      } else {
         var1.b(var2, this.m);
      }

      return var2;
   }

   private void a(int var1, int var2) {
      Iterator var3 = this.f.getColumns().iterator();

      while(var3.hasNext()) {
         Column var4 = (Column)var3.next();
         if (var4.getIndex() >= var2 && var4.e() && var4.c() != 15) {
            this.e = false;
            return;
         }
      }

      zr var9 = this.f.f();
      if (var9.a() < 1) {
         this.e = true;
      } else {
         zahl var10 = var9.b(var1, -1, false);
         if (var10 != null) {
            label47:
            while(true) {
               zahl var5;
               zp var6;
               int var7;
               do {
                  var7 = var10.a();
                  if (var7 < 0) {
                     break label47;
                  }

                  var6 = var9.f(var7);
                  if (Row.e(var6) != 15) {
                     this.e = false;
                     return;
                  }

                  var5 = var6.b(var2, -1, false);
               } while(var5 == null);

               int var8;
               do {
                  var7 = var5.a();
                  if (var7 < 0) {
                     continue label47;
                  }

                  var8 = var6.g(var7);
               } while(var8 == -1 || var8 == 15);

               this.e = false;
               return;
            }
         }

         this.e = true;
      }
   }

   private void a(String var1, int var2, int var3) throws Exception {
      com.aspose.cells.b.a.d.ze var4 = com.aspose.cells.b.a.d.zd.a(var1, 3, 1, 3);
      com.aspose.cells.b.a.d.zn var5 = this.h.d ? new com.aspose.cells.b.a.d.zn(var4) : new com.aspose.cells.b.a.d.zn(var4, this.h.getEncoding());
      if (this.h.c()) {
         this.b(var5, var2, var3);
      } else {
         this.c(var5, var2, var3);
      }

      var5.a();
   }

   private void a(com.aspose.cells.b.a.d.zn var1, int var2, int var3) throws Exception {
      if (this.h.c()) {
         this.b(var1, var2, var3);
      } else {
         this.c(var1, var2, var3);
      }

   }

   private String a(com.aspose.cells.b.a.d.zn var1) throws Exception {
      String var2 = var1.f();
      if (this.h.isMultiEncoded() && this.h.d) {
         if (var2 != null && var2.length() > 0) {
            if (var2.length() == 1 && var2.charAt(0) == 0) {
               return this.a(var1);
            } else {
               char[] var3 = var2.toCharArray();

               for(int var4 = var3[0] == 0 ? 0 : 1; var4 < var3.length; var4 += 2) {
                  if (var3[var4] != 0) {
                     return var2;
                  }
               }

               if (var1.c() == 0) {
                  var1.d();
                  if (var1.c() == 10) {
                     var1.d();
                     if (var1.c() == 0) {
                        var1.d();
                     }
                  }
               }

               return com.aspose.cells.b.a.zv.a(var2, "\u0000", "");
            }
         } else {
            return var2;
         }
      } else {
         return var2;
      }
   }

   private void b(com.aspose.cells.b.a.d.zn var1, int var2, int var3) throws Exception {
      char var4 = this.h.getSeparator();
      var1.b().a(0L, 0);
      zhu.c();
      this.a(var2, var3);
      this.f.a(1000, 50);
      zr var5 = this.f.f();
      zp var6 = null;
      zbbj var7 = new zbbj();
      var7.a(0, this.f);
      int var9 = 0;
      int var10 = var2;
      int var11 = -1;
      boolean var12 = false;
      int var13 = 50;
      int var14 = -1;
      StringBuilder var15 = new StringBuilder();

      while(true) {
         String var16;
         do {
            if (var1.c() == -1) {
               var5.g(-10, 0);
               this.f.g();
               this.f.a((short)var14);
               return;
            }

            var16 = this.a(var1);
         } while(var16 == null);

         if (var9 > var3) {
            var13 = Math.max(var9 - var3 + 1, var13);
         }

         var9 = var3;
         ++var11;
         var11 = var5.a(var10, var11);
         int var8;
         if (var11 < 0) {
            var7.a = var10;
            var11 = var5.a(-var11 - 1, var7, var13);
            var6 = var5.f(var11);
            var8 = 15;
         } else {
            var6 = var5.f(var11);
            var8 = Row.e(var6);
         }

         int var19 = 0;

         for(int var17 = 0; var17 < var16.length(); ++var17) {
            if (var16.charAt(var17) != '"') {
               if (var16.charAt(var17) == var4) {
                  var19 = this.a(var6, var8, var19, var9++, var3, var15);
                  if (var4 == ' ') {
                     ++var17;

                     while(var17 < var16.length()) {
                        if (var16.charAt(var17) != ' ') {
                           --var17;
                           break;
                        }

                        ++var17;
                     }
                  }
               } else {
                  var15.append(var16.charAt(var17));
               }
            } else if (var15.length() != 0) {
               var15.append(var16.charAt(var17));
            } else {
               boolean var18 = true;
               ++var17;

               while(var18) {
                  while(var17 < var16.length()) {
                     switch(var16.charAt(var17)) {
                     case '"':
                        if (var17 + 1 == var16.length()) {
                           var18 = false;
                        } else if (var16.charAt(var17 + 1) == '"') {
                           var15.append(var16.charAt(var17));
                           ++var17;
                        } else {
                           var18 = false;
                        }
                        break;
                     default:
                        var15.append(var16.charAt(var17));
                     }

                     if (!var18) {
                        break;
                     }

                     ++var17;
                  }

                  if (var18) {
                     if (var1.c() == -1) {
                        break;
                     }

                     var15.append("\n");
                     var16 = this.a(var1);
                     var17 = 0;
                  }
               }
            }
         }

         if (var15.length() > 0) {
            this.a(var6, var8, var19, var9++, var3, var15);
         }

         var6.l(0, 0);
         ++var10;
         if (var9 - 1 > var14) {
            var14 = var9 - 1;
         }
      }
   }

   private void c(com.aspose.cells.b.a.d.zn var1, int var2, int var3) throws Exception {
      String var4 = this.h.getSeparatorString();
      var1.b().a(0L, 0);
      zhu.c();
      this.a(var2, var3);
      this.f.a(1000, 50);
      zr var5 = this.f.f();
      zp var6 = null;
      zbbj var7 = new zbbj();
      var7.a(0, this.f);
      int var9 = 0;
      int var10 = var2;
      int var11 = -1;
      boolean var12 = false;
      int var13 = 50;
      int var14 = -1;
      StringBuilder var15 = new StringBuilder();

      while(var1.c() != -1) {
         String var16 = var1.f();
         if (var9 > var3) {
            var13 = Math.max(var9 - var3 + 1, var13);
         }

         var9 = var3;
         ++var11;
         var11 = var5.a(var10, var11);
         int var8;
         if (var11 < 0) {
            var7.a = var10;
            var11 = var5.a(-var11 - 1, var7, var13);
            var6 = var5.f(var11);
            var8 = 15;
         } else {
            var6 = var5.f(var11);
            var8 = Row.e(var6);
         }

         int var20 = 0;

         for(int var17 = 0; var17 < var16.length(); ++var17) {
            boolean var18;
            if (var16.charAt(var17) == '"') {
               if (var15.length() != 0) {
                  var15.append(var16.charAt(var17));
               } else {
                  var18 = true;
                  ++var17;

                  while(var18) {
                     while(var17 < var16.length()) {
                        switch(var16.charAt(var17)) {
                        case '"':
                           if (var17 + 1 == var16.length()) {
                              var18 = false;
                           } else if (var16.charAt(var17 + 1) == '"') {
                              var15.append(var16.charAt(var17));
                              ++var17;
                           } else {
                              var18 = false;
                           }
                           break;
                        default:
                           var15.append(var16.charAt(var17));
                        }

                        if (!var18) {
                           break;
                        }

                        ++var17;
                     }

                     if (var18 && var1.c() != -1) {
                        var15.append("\n");
                        var16 = var1.f();
                        var17 = 0;
                     }
                  }
               }
            } else if (var16.charAt(var17) != var4.charAt(0)) {
               var15.append(var16.charAt(var17));
            } else {
               var18 = true;

               for(int var19 = 1; var19 < var4.length() && var17 + var19 < var16.length(); ++var19) {
                  if (var16.charAt(var17 + var19) != var4.charAt(var19)) {
                     var18 = false;
                     break;
                  }
               }

               if (var18) {
                  var20 = this.a(var6, var8, var20, var9++, var3, var15);
                  var17 += var4.length() - 1;
               } else {
                  var15.append(var16.charAt(var17));
               }
            }
         }

         if (var15.length() > 0) {
            this.a(var6, var8, var20, var9++, var3, var15);
         }

         var6.l(0, 0);
         ++var10;
         if (var9 - 1 > var14) {
            var14 = var9 - 1;
         }
      }

      var5.g(-10, 0);
      this.f.g();
      this.f.a((short)var14);
   }
}
